#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>

int 
main(int argc, char* args[])
{
	//ls | wc -l;
	//ls dup2(f[1], STDOUT_FILENO) execp("ls", "ls", NULL)
	//wc dup2(STDIN_FILENO, f[0])  excep("wc", "wc", "-l", NULL);


	int pid, fd[2] = {3, 4};
	pipe(fd);
	pid = fork();

	if(pid < 0){
		perror("pid error");
		exit(1);
	}
	else if(pid){
		close(fd[0]);
		if(dup2(fd[1], STDOUT_FILENO) < 0){
			perror("dup2 error");
			exit(1);
		}
		execlp("ls", "ls", NULL);
		perror("exce error");
		close(fd[1]);
		exit(1);
	}
	else if(!pid){
		close(fd[1]);
		if(dup2(fd[0], STDIN_FILENO) < 0){
			perror("dup2 error");
			exit(1);
		}
		execlp("wc", "wc", "-l", NULL);
		perror("wc error");
		close(fd[1]);
		exit(1);
	}

	exit(0);
}




//dup2(fd[1], STDOUT_FILENO)
//dup2(STDIN_FIELNO, fd[0])











